package www.lagou.app;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import www.lagou.utils.DruidUtils;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

public class Homework3 {
    public static void main(String[] args) {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
        String demand1 = "select * from employee where did is not null";
        String demand2 = "select e.name, e.salary, d.deptname from employee e inner join dept d on e.did = d.id";
        List<Object[]> employee1 = null;
        List<Object[]> employee2 = null;
        try {
            employee1 = qr.query(demand1, new ArrayListHandler());
            employee2 = qr.query(demand2, new ArrayListHandler());
        } catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println("查询所有的员工信息 (不包含没有部门的员工)");
        for(Object[] o : employee1){
            System.out.println(Arrays.toString(o));
        }
        System.out.println();
        System.out.println("查询每个员工的 姓名, 薪资 和 所属部门名称");
        for(Object[] o : employee2){
            System.out.println(Arrays.toString(o));
        }
    }

}
